<?php

require_once('../../includes/classes/core.php');
$action 	= $_REQUEST['act'];
$error		= '';
$data		= '';

$start		= $_REQUEST['start'];
$end		= $_REQUEST['end'];
$start = $db->convertDateTime($start);
$end = $db->convertDateTime($end); 
switch ($action) {
	case 'get_list' :
		$count = 		$_REQUEST['count'];
		$hidden = 		$_REQUEST['hidden'];
		
	  	$rResult = mysql_query("SELECT   DATE_FORMAT(asterisk_outgoing.call_datetime,'%d/%m/%y %H:%i:%s'),
										 DATE_FORMAT(asterisk_outgoing.call_datetime,'%d/%m/%y %H:%i:%s'),
										 asterisk_outgoing.extension,
										 asterisk_outgoing.phone,
										 crystal_users.`name`,
										 TIME_FORMAT(SEC_TO_TIME(asterisk_outgoing.duration ),'%i:%s') as `time`,
										 CONCAT('<p onclick=play(', '\'', asterisk_outgoing.file_name, '\'',  ')>მოსმენა</p>', '<a download=\"image.jpg\" href=\"http://91.233.15.136:8181/', asterisk_outgoing.file_name, '\">ჩამოტვირთვა</a>')
								FROM      asterisk_outgoing
								LEFT JOIN crystal_users ON crystal_users.id=asterisk_outgoing.user_id
								WHERE     DATE(asterisk_outgoing.call_datetime)  BETWEEN  date('$start')  And date('$end')
									AND     (asterisk_outgoing.phone IN (115, 160, 161) OR asterisk_outgoing.extension IN (115, 160, 161))
								
								UNION all
								
								SELECT   DATE_FORMAT(asterisk_outgoing.call_datetime,'%d/%m/%y %H:%i:%s'),
										 DATE_FORMAT(asterisk_outgoing.call_datetime,'%d/%m/%y %H:%i:%s'),
										 asterisk_outgoing.extension,
										 asterisk_outgoing.phone,
										 crystal_users.`name`,
										 TIME_FORMAT(SEC_TO_TIME(asterisk_outgoing.duration ),'%i:%s') as `time`,
										 CONCAT('<p onclick=play(', '\'', asterisk_outgoing.file_name, '\'',  ')>მოსმენა</p>', '<a download=\"image.jpg\" href=\"http://91.233.15.136:8181/', asterisk_outgoing.file_name, '\">ჩამოტვირთვა</a>')
								FROM      asterisk_outgoing
								LEFT JOIN crystal_users ON crystal_users.id=asterisk_outgoing.user_id
								WHERE     DATE(asterisk_outgoing.call_datetime)  BETWEEN  date('$start')  And date('$end')
									AND     (asterisk_outgoing.phone IN (119,130,150) OR asterisk_outgoing.extension IN (119,130,150))");
	  							
	  	
		$data = array(
				"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
			}
			$data['aaData'][] = $row;
		}

		break;
		
	default:
		$error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);

?>